
<script>
import dmbForm from "@/components/DmbForm";
import dmbTable from "@/components/LTable/index.vue";
import {
  formBase,
  tableBase,
  tableBase2,
  cellStyle,
  headerCellStyle,
  tableFormStyle,
  formItemStyle,
} from "./config";
import dayjs from "dayjs";
const defaultForm = {
  startTime: "",
  endTime: "",
  inventoryEmployee: "",
  monthlyStatistics: "",
  userId: "",
  shopId: "",
};

export default {
  name: "daily-inventory",
  computed: {
    formItemStyle() {
      return formItemStyle;
    },
    tableFormStyle() {
      return tableFormStyle;
    },
    cellStyle() {
      return cellStyle;
    },
    headerCellStyle() {
      return headerCellStyle;
    },
  },
  components: { dmbTable, dmbForm },
  data() {
    return {
      propsSearchForm: { ...defaultForm },
      rebase: formBase,
      requestConfig: {
        url: "/system/dailyInventoryStatistics/list",
        method: "get",
        montage: true,
      },
      requestConfig2: {
        url: "/system/dailyInventoryStatistics/detailsList",
        method: "get",
        montage: true,
      },
      selectionArr: [], // 多选框内容
      selectionArr2: [], // 多选框内容
      tableSearchForm: { ...defaultForm },
    };
  },
  methods: {
    tableBase() {
      return tableBase;
    },
    tableBase2() {
      return tableBase2;
    },
    // 导出
    async downLoad() {
      if (this.selectionArr.length > 0) {
        const arrivalTimes = this.selectionArr.map((v) => v.arrivalTime);
        this.download(
          "/system/dailyInventoryStatistics/export",
          {
            arrivalTimes,
          },
          `每日入库_${dayjs().format("YYYY-MM-DD HH:mm:ss")}.xlsx`
        );
      } else {
        this.$message.error("请选择条数据导出");
      }
    },
    // 导出2
    async downLoad2() {
      if (this.selectionArr2.length > 0) {
        const courierNumbers = this.selectionArr2.map((v) => v.courierNumber);

        this.download(
          "/system/dailyInventoryStatistics/exportDetail",
          { ...this.tableSearchForm, courierNumbers },
          `每日入库详细_${dayjs().format("YYYY-MM-DD HH:mm:ss")}.xlsx`
        );
      } else {
        this.$message.error("请选择条数据导出");
      }
    },
    // 多选框内容
    selectionChange(data) {
      this.selectionArr = data;
    },
    CustomDoubleClick(row) {
      console.log("双击", row);
      this.tableSearchForm = { ...this.tableSearchForm, ...row };
      this.$nextTick(() => {
        this.$refs.table2.getListData();
      });
    },
  },
  watch: {
    propsSearchForm: {
      deep: true,
      handler: function (value) {
        this.tableSearchForm = { ...value };
        delete this.tableSearchForm.shelfTime;
        // 日期
        if (!value?.shelfTime?.length) {
          this.tableSearchForm.startTime = "";
          this.tableSearchForm.endTime = "";
        } else if (value?.shelfTime?.length) {
          this.tableSearchForm.startTime = dayjs(value.shelfTime[0]).format(
            "YYYY-MM-DD HH:mm:ss"
          );
          this.tableSearchForm.endTime = dayjs(value.shelfTime[1]).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        }
      },
    },
  },
};
</script>
<template>
  <div>
    <div class="overflow-auto">
      <dmb-form
        ref="form"
        :form-items="rebase"
        :model-value="propsSearchForm"
        :item-style="formItemStyle"
        @update="(row) => (propsSearchForm = row)"
      >
        <template v-slot:header="row" class="flex flex-row-reverse">
          <div class="mb-3 flex flex-row-reverse">
            <div>
              <el-button type="success" @click="$refs.table.getListData()"
                >查询</el-button
              >
              <el-button type="primary" @click="downLoad">导出统计表</el-button>
              <el-button type="primary" @click="downLoad2"
                >导出详细表</el-button
              >
            </div>
          </div>
        </template>
      </dmb-form>
    </div>
    <div class="font-600 mb-4">双击左边表格的一行，可以查看明细</div>
    <div class="overflow-auto flex">
      <div class="son mr-4">
        <dmb-table
          ref="table"
          :CustomDoubleClick="true"
          @CustomDoubleClick="CustomDoubleClick"
          :prop-list="tableBase()"
          :show-index-column="true"
          select-column-type="CHECKBOX"
          :props-search-form="tableSearchForm"
          :req-request="requestConfig"
          select-key="id"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          :initialize="false"
          :change-search-form="false"
          :show-footer="true"
          :form-item-style="tableFormStyle"
          @selectionChange="
            (row) => {
              selectionArr = row;
            }
          "
        />
      </div>
      <div class="son">
        <dmb-table
          ref="table2"
          :CustomDoubleClick="true"
          :prop-list="tableBase2()"
          :show-index-column="true"
          select-column-type="CHECKBOX"
          :props-search-form="tableSearchForm"
          :req-request="requestConfig2"
          select-key="id"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          :initialize="false"
          :change-search-form="false"
          :show-footer="true"
          :form-item-style="tableFormStyle"
          @selectionChange="
            (row) => {
              selectionArr2 = row;
            }
          "
        />
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.son {
  overflow: auto;
}
</style>
